// WebSocket模块

const socketIO = require('socket.io')
const db = require('../config/mysql.js')
const utils = require("../common/utils")

let io

const initSocket = (server) => {
  io = socketIO(server, {
    allowEIO3: true,
    cors: true
  });
  // 连接用户数量
  let count = 0
  // 连接用户
  let connections = []
  
  let intervalId = null
  
  io.on('connection', (socket) => {
    console.log("Socket connected")
    
    socket.on('disconnect', () => {
      console.log('Socket disconnected');
      clearInterval(intervalId);
    })
  })
}

module.exports = {
  initSocket
}
